package com.carrie.mdg.myviewtext.activity;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.carrie.mdg.myviewtext.R;

import java.io.File;

public class NotificationTestActivity extends AppCompatActivity {

    private Button btnSend;

    public static void actionStart(Context context) {
        Intent intent = new Intent(context, NotificationTestActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notification_test);
        btnSend = (Button) findViewById(R.id.send_notice);
        btnSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

                NotificationManagerCompat managerCompat = NotificationManagerCompat.from(NotificationTestActivity.this);

                Intent intent = new Intent(NotificationTestActivity.this, NotificationActivity.class);
                PendingIntent pi = PendingIntent.getActivity(NotificationTestActivity.this, 0, intent, 0);

                Notification notification = new NotificationCompat.Builder(NotificationTestActivity.this)
                        .setContentTitle("This is content title")
//                        .setContentText("")
//                        .setStyle(new NotificationCompat.BigTextStyle().bigText("Learn how to build notifications, send and sync data, and " +
//                                "use voice actions. Get the offical Android IDE and developer tools to" +
//                                "build apps for Android."))
                        .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(BitmapFactory.decodeResource(getResources(),R.drawable.cats)))
                        .setWhen(System.currentTimeMillis())
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                        .setContentIntent(pi)
                        .setAutoCancel(true)
                        .setVibrate(new long[]{0, 1000, 1000, 1000})
                        .setLights(Color.GREEN, 1000, 1000)
                        .setSound(Uri.fromFile(new File("/system/media/audio/ringtones/Lotus.ogg")))
                        .setPriority(NotificationCompat.PRIORITY_HIGH)
                        .build();
//                        .setDefaults(NotificationCompat.DEFAULT_ALL)
//                manager.notify(1,notification);
                managerCompat.notify(2, notification);
            }
        });
    }
}
